<?php


namespace app\api\model;


use app\common\model\BaseModel;
use common;

class ArticleCateModel extends BaseModel
{
    protected $name ='article_cate';
    protected $pk = 'id';

    var $_selectlist = [
        'id' => 'int',
        'name' => 'string',
        'visitable' => 'int',
        'icon' => 'string',
        'rank' => 'int',
        'state' => 'int',
    ];

    function add($info)
    {
        $info = common::type_conver($info, $this->_selectlist);
        $info['state'] = 0;

        self::create($info,true);
    }


    function query_list($cd)
    {
        $beans =[
            'state' =>0,
        ];

        if (isset($cd['visitable'])){
            $beans['visitable'] = $cd['visitable'];
        }

        return $this->where($beans)->order('rank')->field(common::array_keys($this->_selectlist))->select();
    }

    function update_article($id, $info)
    {
        $sl = $this->_selectlist;
        unset($sl['id']);


        $info = common::type_conver($info, $sl);

        $where = [
            'id' => $id,
        ];

        $this->where($where)->update($info);
        //hisql::update('tb_article_cate', $info, $where);
    }

}